home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / HoweExample4.c < prev    next >
Text File  |  1990-08-07  |  2KB  |  101 lines

  1. /*
  2. * ⌐ Graeme Gerrard 1990
  3. * Faculty of Music, University of Melbourne
  4. * Parkville Victoria 3052 Australia.
  5. *
  6. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  7. * telephone: (613) 344 4127, Fax: (613) 344 5346
  8. */
  9.  
  10.  
  11. #include    "Music4C.h"
  12. #include    <math.h>
  13. #include    "ugens.h"
  14. #include    "orch.h"
  15.  
  16. #define    MAXINS        5
  17.  
  18. static    double    *a;
  19. static    long    sampno;
  20. static    long    base;
  21. extern    Str255    theMess1;
  22.  
  23.  
  24. void initl()
  25. {
  26.     register long    j;
  27.     a = (double *)NewPtr(MAXINS * 10 * sizeof(double));
  28.     if ( a == 0L )
  29.         fprintf(stderr, "Not enough memory in initl\n");
  30.     for ( j = 0; j < MAXINS * 10; j++ )
  31.         *(a+j) = 0.0;
  32. }
  33.  
  34.  
  35. void setup()
  36. {
  37. /*
  38. * p4 = amp
  39. * p5 = carrier freq in cps
  40. * p6 = mod freq in cps
  41. * p7 = first val of mod index
  42. * p8 = final val of mod index
  43. *
  44. * F1 = sine
  45. * F2 = amp env
  46. * F3 = freq dev envelope
  47. */
  48.     if ( insno > MAXINS ) {
  49.         sprintf((char *)theMess1, "Instrument number %d is out of range", insno);
  50.         CtoPstr((char *)theMess1);
  51.         OSError(theMess1, NIL, NIL );
  52.     }
  53.     base = ((insno-1) * 10);
  54.     *(a+base) = period(p[3]);
  55. /* Multiply by 30,000 so that we generate a reasonable amplitude for
  56. * SD files, which are ▒32767 */
  57.     *(a+base+1) = p[4] * 30000.0;
  58.     *(a+base+2) = 0.0;
  59.     *(a+base+3) = cycle((p[8] - p[7]) * p[6]);
  60.     *(a+base+4) = 0.0;
  61.     *(a+base+5) = cycle(p[7] * p[6]);
  62.     *(a+base+6) = cycle(p[6]);
  63.     *(a+base+8) = cycle(p[5]);
  64. }
  65.  
  66. void orch()
  67. {
  68.     register    double    x;
  69.     register    double    y;
  70.     register    base;
  71.     
  72.     base = ((insno-1) * 10);
  73. /*    x = oscil1(*(a+base+1), *(a+base), 2, (a+base+2));
  74.     y = oscil1(*(a+base+3), *(a+base), 3, (a+base+4)) + *(a+base+5);
  75.     y = oscil(y, *(a+base+6), 1, (a+base+7)) + *(a+base+8);
  76.     x = oscil(x, y, 1, (a+base+9));
  77.     mono(x);
  78. */
  79. /* in this case using the macros saves about 30% on the function call time */
  80.     Oscil1(x, *(a+base+1), *(a+base), 2, *(a+base+2));
  81.     Oscil1(y, *(a+base+3), *(a+base), 3, *(a+base+4));
  82.     y += *(a+base+5);
  83.     Oscil(y, y, *(a+base+6), 1, *(a+base+7));
  84.     y += *(a+base+8);
  85.     Oscil(x, x, y, 1, *(a+base+9));
  86.     Mono(x);
  87. }
  88.  
  89.  
  90. void ter()
  91. {
  92.     /* just gets called at the end a note for clean up etc. */
  93. }
  94.  
  95. void final()
  96. {
  97. /* called at the end of the synth run.
  98. *  close any files etc. you haven't already closed here.
  99. */
  100. }
  101.